﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ZedGraph;

namespace erse253_homework
{
    public partial class ChartMovingWindow : BaseWindowChart
    {
        double[,] data;

        public ChartMovingWindow(double[,] data)
        {
            InitializeComponent();
            this.data = data;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int size;
            if (data != null)
            {
                Cursor.Current = Cursors.WaitCursor;
                if (int.TryParse(textBox1.Text, out size) && size >= 2 && size <= data.GetLength(0) && size <= data.GetLength(1))
                    CalculateStatisticalParametersMovingWindow(size);

                Cursor.Current = Cursors.Default;
            }
        }

        private void CalculateStatisticalParametersMovingWindow(int size) 
        {
            int divisionsX;
            int divisionsY;
            double[,] mean;
            double[,] stdDevian;

            SetParameters(size, out divisionsX, out divisionsY, out mean, out stdDevian);


            //this function is now inside the chart class.
            //CalculateMeanStdDeviation(size, divisionsX, divisionsY, mean, stdDevian);

            //the zedGraphControl is a component developed by a third party programmer. (I'm using it here to speed up my development task).
            base.ClearList();

            //FormatScatterplot(x, mean,  "Mean", Color.Red);
            //FormatScatterplot(x, stdDevian,  "Standard Deviation", Color.Blue);
        }

        private void SetParameters(int size, out int divisionsX, out int divisionsY, out double[,] mean, out double[,] stdDevian)
        {
            divisionsX = (data.GetLength(0) - size) / (size / 2) + 1;
            divisionsY = (data.GetLength(1) - size) / (size / 2) + 1;

            mean = new double[divisionsX , divisionsY];
            stdDevian = new double[divisionsX , divisionsY];

        }


        private void FormatScatterplot(double[] x, double[] y,  string name, Color color)
        {

            LineItem myCurve =new LineItem(name, x, y, color, SymbolType.Circle);

            myCurve.Line.IsVisible = true;
            myCurve.Symbol.Size = 3.0F;
            myCurve.Symbol.Fill = new Fill(color);

            base.AddItem(myCurve, "Data Profile", "Position", "Value", "Chart moving window");
        }
    }
}
